USE Liberty
GO

-- ------------------------------------------------------------------------------------------------
-- GrantAssignments Table Create Script
-- ------------------------------------------------------------------------------------------------
SET NOCOUNT OFF
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
SET ARITHABORT ON
SET CONCAT_NULL_YIELDS_NULL ON
SET QUOTED_IDENTIFIER ON
SET NUMERIC_ROUNDABORT OFF
GO

PRINT 'Creating Table dbo.GrantAssignments...'
GO

IF OBJECT_ID('dbo.GrantAssignments', 'U') IS NULL
BEGIN
	CREATE TABLE dbo.GrantAssignments
	(OID				bigint		IDENTITY(1, 1)	NOT NULL
	,Version			rowversion
	,GrantID			bigint			NOT NULL
	,UserID				bigint			NOT NULL

	,UpdatedDate		datetime					NOT NULL
		CONSTRAINT DFLT_GrantAssignments_UpdatedDate DEFAULT GETDATE()
	,CreatedDate		datetime					NOT NULL
		CONSTRAINT DFLT_GrantAssignments_CreatedDate DEFAULT GETDATE()

	,CONSTRAINT PK_GrantAssignments PRIMARY KEY CLUSTERED( OID ) --ON PRIMARY

	,CONSTRAINT FK_GrantAssignments_Grants FOREIGN KEY (GrantID)
		REFERENCES Grants(OID)

	,CONSTRAINT FK_GrantAssignments_Users FOREIGN KEY (UserID)
		REFERENCES Users(OID)

	)

	PRINT 'Table dbo.GrantAssignments has been created successfully.'

END
ELSE 
BEGIN
    PRINT 'Table dbo.GrantAssignments already exists.'
END

GO
